using System;
using System.Collections.Generic;
using System.Linq;

namespace Common
{
    public struct IOState
    {
        public bool io0;
        public bool io1;
        public bool io2;
        public bool io3;
        public bool io4;
        public bool io5;
        public bool io6;
        public bool io7;
        public bool io8;
        public bool io9;
        public bool io10;
        public bool io11;
        public bool io12;
        public bool io13;
        public bool io14;
        public bool io15;
        public override string ToString()
        {
            string ret="" ;
            for (int i = 0; i < 16; i++)
            {
                ret += this[i] ? "1" : "0";
            }
           return ret;
        }
        public IOState(int lpBitPattern)
        {
            io0 = (lpBitPattern & 0x01) > 0 ? true : false;
            io1 = (lpBitPattern >> 1 & 0x01) > 0 ? true : false;
            io2 = (lpBitPattern >> 2 & 0x01) > 0 ? true : false;
            io3 = (lpBitPattern >> 3 & 0x01) > 0 ? true : false;
            io4 = (lpBitPattern >> 4 & 0x01) > 0 ? true : false;
            io5 = (lpBitPattern >> 5 & 0x01) > 0 ? true : false;
            io6 = (lpBitPattern >> 6 & 0x01) > 0 ? true : false;
            io7 = (lpBitPattern >> 7 & 0x01) > 0 ? true : false;
            io8 = (lpBitPattern >> 8 & 0x01) > 0 ? true : false;
            io9 = (lpBitPattern >> 9 & 0x01) > 0 ? true : false;
            io10 = (lpBitPattern >> 10 & 0x01) > 0 ? true : false;
            io11 = (lpBitPattern >> 11 & 0x01) > 0 ? true : false;
            io12 = (lpBitPattern >> 12 & 0x01) > 0 ? true : false;
            io13 = (lpBitPattern >> 13 & 0x01) > 0 ? true : false;
            io14 = (lpBitPattern >> 14 & 0x01) > 0 ? true : false;
            io15 = (lpBitPattern >> 15 & 0x01) > 0 ? true : false;

        }
        public bool this[int index]
        {
            get
            {
                if (index < 16 && index > -1)
                {
                    if (index == 0)
                        return io0;
                    else if (index == 1)
                        return io1;
                    else if (index == 2)
                        return io2;
                    else if (index == 3)
                        return io3;
                    else if (index == 4)
                        return io4;
                    else if (index == 5)
                        return io5;
                    else if (index == 6)
                        return io6;
                    else if (index == 7)
                        return io7;
                    else if (index == 8)
                        return io8;
                    else if (index == 9)
                        return io9;
                    else if (index == 10)
                        return io10;
                    else if (index == 11)
                        return io11;
                    else if (index == 12)
                        return io12;
                    else if (index == 13)
                        return io13;
                    else if (index == 14)
                        return io14;
                    else if (index == 15)
                        return io15;
                    else
                        return false;
                }
                else
                {
                    return false;
                    throw new Exception("iostate index out of range");                  
                }
            }
            set
            {
                if (index < 16 && index > -1)
                {
                    if (index == 0)
                    {
                        io0 = value;
                    }
                    else if (index == 1)
                    {
                        io1 = value;
                    }
                    else if (index == 2)
                    {
                        io2 = value;
                    }
                    else if (index == 3)
                    {
                        io3 = value;
                    }
                    else if (index == 4)
                    {
                        io4 = value;
                    }
                    else if (index == 5)
                    {
                        io5 = value;
                    }
                    else if (index == 6)
                    {
                        io6= value;
                    }
                    else if (index == 7)
                    {
                        io7 = value;
           
                    }
                    else if (index == 8)
                    {
                        io8 = value;
                    }
                    else if (index == 9)
                    {
                        io9 = value;
                    }
                    else if (index == 10)
                    {
                        io10 = value;
                    }
                    else if (index == 11)
                    {
                        io11 = value;

                    }
                    else if (index == 12)
                    {
                        io12 = value;
                    }
                    else if (index == 13)
                    {
                        io13 = value;
                    }
                    else if (index == 14)
                    {
                        io14 = value;
                    }
                    else if (index == 15)
                    {
                        io15 = value;

                    }
                    
                
                }
                else
                {
                    throw new Exception("iostate index out of range");
                }            
            }
        }
    };
}
